<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myProfiles.css"/>
    <title>签到</title>
    <link rel="stylesheet" href="/js/signin/public.css">
    <link rel="stylesheet" href="/js/signin/signin.css">
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/checkLogin.js"></script>
</head>

<body>


<div class="top flex flex-align-end flex-pack-center flex-warp">
    <div class="nav-search">
        <a href="/mine/profiles.html">
            <span><i class="fa fa-angle-left fa-2x"></i></span>
        </a>
    </div>
    <div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
        <div class="out-2 flex flex-align-center flex-pack-center">
            <div class="signBtn">
                <strong id="sign-txt">签到</strong>
                <span>连续<em id="sign-count">0</em>天</span>
            </div>
        </div>
    </div>
</div>
<div class="tips"><p id="tips">签到可获得个积分喔</p></div>
<div class="Calendar">
    <div id="toyear" class="flex flex-pack-center">
        <div id="idCalendarPre">&lt;</div>
        <div class="year-month">
            <span id="idCalendarYear">2018</span>年<span id="idCalendarMonth">11</span>月
        </div>
        <div id="idCalendarNext">&gt;</div>
    </div>
    <table border="1px" cellpadding="0" cellspacing="0">
        <thead>
        <tr class="tou">
            <td>日</td>
            <td>一</td>
            <td>二</td>
            <td>三</td>
            <td>四</td>
            <td>五</td>
            <td>六</td>
        </tr>
        </thead>
        <tbody id="idCalendar">
        <tr>
            <td><span>&nbsp;</span></td>
            <td><span>&nbsp;</span></td>
            <td><span>&nbsp;</span></td>
            <td><span>&nbsp;</span></td>
            <td><span>1</span></td>
            <td><span>2</span></td>
            <td><span>3</span></td>
        </tr>
        <tr>
            <td><span>4</span></td>
            <td><span>5</span></td>
            <td><span>6</span></td>
            <td><span>7</span></td>
            <td><span>8</span></td>
            <td><span>9</span></td>
            <td><span>10</span></td>
        </tr>
        <tr>
            <td><span>11</span></td>
            <td><span>12</span></td>
            <td><span>13</span></td>
            <td><span>14</span></td>
            <td><span>15</span></td>
            <td><span>16</span></td>
            <td><span>17</span></td>
        </tr>
        <tr>
            <td><span>18</span></td>
            <td><span>19</span></td>
            <td><span>20</span></td>
            <td><span>21</span></td>
            <td><span>22</span></td>
            <td><span>23</span></td>
            <td><span>24</span></td>
        </tr>
        <tr>
            <td><span>25</span></td>
            <td><span>26</span></td>
            <td><span>27</span></td>
            <td><span>28</span></td>
            <td><span>29</span></td>
            <td><span>30</span></td>
            <td>&nbsp;</td>
        </tr>
        </tbody>
    </table>

</div>
<script type="text/javascript" src="/js/signin/rili.js"></script>
<script language="JavaScript">
    $(function () {
        var user = JSON.parse(sessionStorage.getItem("user"));//得到的是登录的用户的信息
        console.log(user);
        var isSign = false;//验证是否签到
        $.get(baseUrl+"/signins/",{"userId":user.id} ,function (data) {
            console.log(data);
            if (data) {
                //console.log(data);
                var date = new Date();
                console.log(date);

                var dataTime=new Date(data.time)
                console.log(dataTime.getDate());
                if ((dataTime.getFullYear() == date.getFullYear()) & (dataTime.getMonth()+1 == date.getMonth() + 1) & (dataTime.getDate() == date.getDate())) {
                    $("#sign-txt").html("已签到");
                    $("#tips").html("今天已签到,获得积分");
                    isSign = true;//已经签到
                    cale.SignIn()
                }
                // var dataTime=new Date(data.time)
                // console.log(dataTime);
                // var arr = [];
                // arr = (dataTime.toLocaleString().split("/"))
                // console.log(arr);
                // if ((arr[0] == date.getFullYear()) & (arr[1] == date.getMonth() + 1) & (arr[2] == date.getDate())) {
                //     $("#sign-txt").html("已签到");
                //     $("#tips").html("今天已签到,获得10积分");
                //     isSign = true;//已经签到
                //     cale.SignIn()
                // }
                $("#sign-count").html(data.count);//连续签到天数
            }
        });
        var myday = new Array(); //已签到的数组
        // myday[0]="1559373300000"
        console.log(user.id);
        if(user.id==1){
            myday[0]="1559373852"
            myday[1]="1559461119"
            myday[2]="1559523829"
        }else if(user.id==2){
            myday[0]="1559373852"
            myday[1]="1559461119"
        }

        // var myday = new Array(); //已签到的数组
        			// myday[0] = "1528646400"
        			// myday[1] = "1528387200"
        			// myday[2] = "1525708800"

        var cale = new Calendar("idCalendar", {
            qdDay: myday,
            onToday: function (o) {
                o.className = "onToday";
            },
            onSignIn: function () {
                $$("sign-txt").innerHTML = '已签到';
            },
            onFinish: function () {
                $$("sign-count").innerHTML = myday.length //已签到次数
                $$("idCalendarYear").innerHTML = this.Year;

                $$("idCalendarMonth").innerHTML = this.Month; //表头年份

            }
        });
        //处理点击月份的跳转
        $$("idCalendarPre").onclick = function () {
            cale.PreMonth();
        }
        $$("idCalendarNext").onclick = function () {
            cale.NextMonth();
        }
        //添加今天签到,点击事件
        $$("signIn").onclick = function () {
            if (isSign == false) {
                var res = cale.SignIn();
                if (res == '1' & ($("#sign-txt").html1 != '已签到')) {
                    $$("sign-txt").innerHTML = '已签到';
                    $$("sign-count").innerHTML = parseInt($$("sign-count").innerHTML) + 1;
                    isSign = true;
                    $("#tips").html("今天已签到,获得积分1");
                    $(document).dialog({
                        type: 'notice',
                        content: '<span class="info-text">恭喜您,积分+10!</span>',
                        autoClose: 1000,
                        position: 'center'
                    });
                    //修改签到
                    $.post(baseUrl+"/signins",{"user.id":user.id} ,function (data) {

                    });
                } else if (res == '2') {
                    $$("sign-txt").innerHTML = '已签到';
                    alert('今天已经签到了')
                }
            } else {
                $(document).dialog({
                    titleText: '温馨提示',
                    content: '您今天已经签到啦!',
                });
            }
            location.reload()

        }
    });
</script>


</body>
</html>